package libtool65.link;

import libtool65.o65.Module;

public class ModuleDefinition {
	private String	name;
	private Module	module;
	private int		base_address = -1;
	private int		bss_offset = -1;
	private int		zp_offset = -1;
	
	ModuleDefinition(String name, Module module)
	{
		this.name = name;
		this.module = module;
	}
	
	public String getName() {
		return name;
	}

	public Module getModule() {
		return module;
	}

	public void setBaseAddress(int base_address) {
		this.base_address = base_address;		
	}
	
	public int getTextAddress()
	{
		return base_address + getModule().getTextOffset();
	}
	
	public int getDataAddress()
	{
		return base_address + getModule().getDataOffset();
	}
	
	public int getBssAddress()
	{
		return bss_offset;
	}

	public int calcBssOffset(int old_bss_offset) {
		if (getModule().isBssZeroFilled())
		{
			bss_offset  = base_address + getModule().getBssOffset();
			return old_bss_offset;
		}
		return old_bss_offset + getModule().getBssOffset();
	}

	public int copyCode(byte[] code_block, int current_offset) {
		current_offset = getModule().copyText(code_block, current_offset);
		current_offset = getModule().copyData(code_block, current_offset);
		current_offset = getModule().copyBss(code_block, current_offset);
		return current_offset;
	}

	public int calcZpOffset(int zp_offset) {
		this.zp_offset = zp_offset;
		return zp_offset + getModule().getZpSize();
	}
	
	public int getZpAddress()
	{
		return zp_offset;
	}
}
